package cz.techi;

//import cz.techi.ScheduleLoader;

import java.util.Calendar;
import java.util.Date;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TableLayout;
import android.widget.TableLayout.LayoutParams;
import android.widget.TableRow;
import android.widget.TextView;
public class ScheduleActivity extends Activity {
	
	private Subject[] subjects;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my);

        TableLayout tl = (TableLayout)findViewById(R.id.myTab);

        

        Schedule schedule = Schedule.getInstance();
        
        
        subjects = schedule.getSubjects();
        
        
        Calendar cal = Calendar.getInstance();
        Date date = new Date();
        
        String day = "";
        StringBuffer str = new StringBuffer();
        
        if (subjects != null)
        {
        
	        for (Subject subject: subjects)
	        {
	
	            TableRow tr = new TableRow(this);
	            
	            
	            TextView tv = new TextView(this);
	            
	            str.delete(0, str.length());

	            
	            if (!day.equals(subject.day))
	            {
	            	str.append("\n" + subject.getLocalizedDay() + "\n");
	            	day = subject.day;
	            }
	            
	            str.append(subject.from + "-" + subject.to + "\n");
	            
	            str.append(subject.ident + " "+ subject.name);
	            str.append("\n" + subject.room + " " + subject.type);
	            
	            tv.setText(str);
	
	            
	            tr.addView(tv);
	            
	            
	            
	            tl.addView(tr,new TableLayout.LayoutParams(
	                    LayoutParams.FILL_PARENT,
	                    LayoutParams.WRAP_CONTENT));
	
	        }
	        
        }
        
        
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        
        return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    	
    	return MenuHandler.handle(this, item);
    }
}